<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\constant\api;
use app\common\RestController;
class AccessUserRole extends RestController{
    //修改用户角色
    public function updateRole(){
         $code=$data=$message=api\SUCCESS;
	 	 $input=request()->param();
	 	 // return json($input);
         $result=$this->validate($input,'RbacVerify.upRole');
         if($result===true){
               //修改角色与用户关联表即可
         	   $res=Db::table('role_user')->where('user_id',$input['user_id'])->update(['role_id'=>$input['role_id']]);
         	   if(!$res){
         	   	  $code=api\USER_UP_ERROR;
         	   }
         }else{
         	$code=api\FAIL;
         	$message=$result;
         }
         return $this->setDirreturnVars($code,$message,$data);
    }
    //添加用户角色
    public function addRole(){
        $code=$data=$message=api\SUCCESS;
         $input=request()->param();
    
         $result=$this->validate($input,'RbacVerify.addRole');
         if($result===true){
              return json($input);
         }else{
            $code=api\FAIL;
            $message=$result;
         }
         return $this->setDirreturnVars($code,$message,$data);
    }
}